/*
	setup_IDT_64.c

	contains code to setup a black long mode IDT and load it into the IDTR

	Author: Aidan Goddard, 6/5/13
*/

#include "../kernel/headers/types.h"

typedef struct
{
	uint16_t idt_limit;
	uint64_t idt_base;
} __attribute__((__packed__))IDTR;

// function to setup the IDT at 0x100700000 and register it
void SetupIDT()
{
	// zero 4kb of memory at 0x100700000
	uint64_t* ptr = (uint64_t*)(0x700000 + KOFFSET);
	int i;
	for(i = 0; i < 512; i++)
	{
		ptr[i] = 0;
	}


	// load IDTR into processor
	IDTR idtr;
	idtr.idt_limit = 0x1000;
	idtr.idt_base = (0x700000 + KOFFSET);

	__asm__ __volatile__("lidt (%0)"::"p" (&idtr));

	return;
}
